<template>
    <div>
      <div class="inform-main">
        <p class="inform-header">全部消息（{{totalCount}}）</p>
        <myComment v-for="(item,index) in commentList" :key="index" :item="item" :del="false"></myComment>
      </div>
      <bottoms></bottoms>
    </div>
</template>

<script>
  import myComment from "@/components/myComment/inform"
  import bottoms from '@/components/reachBottom/index'
    export default {
        name: "inform",
      components:{
        myComment,
        bottoms
      },
      data(){
        return{
          num:620,
          commentList:[],
          loadingEnd:{
            moduleOne: false,
          },
          totalPage: 1,
          currentPage: 1,
          totalCount: 0
        }
      },
      methods: {
        getInfoList() {
          this.$ajax
            .post(this.$api.getNoticeList, {page: this.currentPage})
            .then(res => {
              console.log(res.data)
              this.loadingEnd.moduleOne = true
              this.commentList.push(...res.data);
              this.totalPage = res.total_page
              this.totalCount = res.total_count
              if(res.total_count === 0){
                this.$store.dispatch("changeIsEmpty", true);
              } else {
                this.$store.dispatch("changeIsEmpty", false);
              }
            })
            .catch(err => {
              this.loadingEnd.moduleOne = true
              ﻿uni.showToast({
                title: err,
                icon: 'none',
                duration: 2000
              })
            });
        },
        viewLoad(){
          this.currentPage = 1
          this.commentList = []
          this.$store.dispatch("changeIsMore", false);
          this.$store.dispatch("changeIsEnd", false);
          this.$store.dispatch("changeIsEmpty", false);
          this.loadingEnd = {
            moduleOne: false,
          };
          ﻿uni.showLoading({
            title: '加载中',
            mask: true
          });
          this.getInfoList();
        }
      },
      computed:{
        hideLoading(){
          if(this.loadingEnd.moduleOne){
            setTimeout(function(){
              ﻿uni.hideLoading()
            }, 800)
          }
        }
      },
      onPullDownRefresh(){
        this.viewLoad()
        ﻿uni.stopPullDownRefresh() //停止下拉刷新
      },
      onReachBottom(){
        if(this.totalPage > this.currentPage){
          this.$store.dispatch("changeIsMore", true);
          this.$store.dispatch("changeIsEnd", false);
          this.currentPage++
          this.getInfoList();
        } else {
          this.$store.dispatch("changeIsEnd", true);
          this.$store.dispatch("changeIsMore", false);
        }
      },
      onLoad() {
        this.viewLoad()
      }
    }
</script>

<style scoped>
  .inform-main{
    padding-bottom: 30rpx;
    box-sizing: border-box;
  }
  .inform-header{
    background-color: #F6F6F8;
    padding: 18rpx 30rpx;
    box-sizing: border-box;
    font-size: 22rpx;
    color: #A7A6AE;
    font-weight: bold;
  }
</style>
